import 'package:appinio_video_player/appinio_video_player.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      debugShowCheckedModeBanner: false,
      theme: CupertinoThemeData(
        brightness: Brightness.light,
      ),
      title: 'Appinio Video Player Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  late CachedVideoPlayerController _videoPlayerController;

  late CustomVideoPlayerController _customVideoPlayerController;
  late CustomVideoPlayerWebController _customVideoPlayerWebController;

  final CustomVideoPlayerSettings _customVideoPlayerSettings =
      const CustomVideoPlayerSettings(showSeekButtons: true);

  final CustomVideoPlayerWebSettings _customVideoPlayerWebSettings =
      CustomVideoPlayerWebSettings(
    src: longVideo,
  );

  @override
  void initState() {
    super.initState();

    _videoPlayerController = CachedVideoPlayerController.network(
      longVideo,
    )..initialize().then((value) => setState(() {}));
    _customVideoPlayerController = CustomVideoPlayerController(
      context: context,
      videoPlayerController: _videoPlayerController,
      customVideoPlayerSettings: _customVideoPlayerSettings
    );

    _customVideoPlayerWebController = CustomVideoPlayerWebController(
      webVideoPlayerSettings: _customVideoPlayerWebSettings,
    );
  }

  @override
  void dispose() {
    _customVideoPlayerController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(
        middle: Text("Appinio Video Player"),
      ),
      child: SafeArea(
        child: Container(
          color: Colors.black,
          alignment: Alignment.center,
          child: kIsWeb
              ? Expanded(
                  child: CustomVideoPlayerWeb(
                    customVideoPlayerWebController: _customVideoPlayerWebController,
                  ),
                )
              : CustomVideoPlayer(
                  customVideoPlayerController: _customVideoPlayerController,
                ),
        ),
      ),
    );
  }
}

String videoUrlLandscape =
    "https://imyf.pointlinkprox.com/v1/Tenant/483/MediaFiles/28de34fd-05d6-47f3-ac11-7e91ceedb6b3YW5pbWF0ZS5tcDQ=";
String videoUrlPortrait =
    'https://imyf.pointlinkprox.com/v1/Tenant/483/MediaFiles/28de34fd-05d6-47f3-ac11-7e91ceedb6b3YW5pbWF0ZS5tcDQ=';
String longVideo =
    "https://imyf.pointlinkprox.com/v1/Tenant/483/MediaFiles/28de34fd-05d6-47f3-ac11-7e91ceedb6b3YW5pbWF0ZS5tcDQ=";

String video720 =
    "https://imyf.pointlinkprox.com/v1/Tenant/483/MediaFiles/28de34fd-05d6-47f3-ac11-7e91ceedb6b3YW5pbWF0ZS5tcDQ=";

String video480 =
    "https://imyf.pointlinkprox.com/v1/Tenant/483/MediaFiles/28de34fd-05d6-47f3-ac11-7e91ceedb6b3YW5pbWF0ZS5tcDQ=";

String video240 =
    "https://imyf.pointlinkprox.com/v1/Tenant/483/MediaFiles/28de34fd-05d6-47f3-ac11-7e91ceedb6b3YW5pbWF0ZS5tcDQ=";
